-
-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: improve processSlashings #6121
Conversation
Performance Report✔️ no performance regression detected 🚀🚀 Significant benchmark improvement detected
Full benchmark results
|
const slashingIndex = epoch % EPOCHS_PER_SLASHINGS_VECTOR; | ||
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + BigInt(effectiveBalance)); | ||
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + effectiveBalance); | ||
epochCtx.totalSlashingsByIncrement += effectiveBalanceIncrements[slashedIndex]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can effectiveBalanceIncrements[slashedIndex]
be undefined? may be worth adding ?? 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
effectiveBalanceIncrements
is populated with validator count and increased its length per processDeposit
so the default value for any validator index is always 0
I also doubled check all use of effectiveBalanceIncrements
, we don't need to handle undefined
there so I think we don't need to do it here too. For example
epochCtx.currentTargetUnslashedBalanceIncrements += effectiveBalanceIncrements[index]; |
const slashingIndex = epoch % EPOCHS_PER_SLASHINGS_VECTOR; | ||
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + BigInt(effectiveBalance)); | ||
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + effectiveBalance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can state.slashings.get(slashingIndex)
be undefined? may be worth adding ?? 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it 👍
@wemeetagain @dapplion in the last commit I added reasoning on how |
@dapplion I addressed the comment in ac08e7d#r133684342 |
🎉 This PR is included in v1.13.0 🎉 |
Motivation
processSlashings()
which only run when there are validators getting slashedDescription
state.slashings
:processSlashings
state.slashings
as number[] instead of BigInt[]processRewardsAndPenalties
part of #6112
part of #5892
Testing
processSlashing()
to almost zero cost.